package com.example.springbootdemo.i18n;

import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;
public class CustomLocaleResolver extends AcceptHeaderLocaleResolver {

    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        // 在这里进行自定义的Locale解析逻辑，例如从数据库中获取用户的偏好设置
        Locale locale = super.resolveLocale(request);
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
        // 在这里进行自定义的设置Locale逻辑，例如将用户的语言偏好存储到数据库中

        // 这里只是一个示例，没有特定的逻辑
        super.setLocale(request, response, locale);
    }
}